/**
 * @file stack.cpp
 * @author 逆流 (1171267147@qq.com)
 * @brief statck.hpp测试文件
 * @version 0.1
 * @date 2024-10-15
 *
 * @copyright Copyright (c) 2024
 *
 */

#include <gtest/gtest.h>

#include "stl/container/stack.hpp"

using stl::Stack;

TEST(Stack, Init) {
    Stack<int> stack1;
    EXPECT_TRUE(stack1.Empty());
    EXPECT_EQ(stack1.length(), 0);

    Stack<int> stack2{1, 2, 3, 4, 5};
    EXPECT_FALSE(stack2.Empty());
    EXPECT_EQ(stack2.length(), 5);
    EXPECT_EQ(stack2.Top(), 5);
    stack2.Clear();
    EXPECT_TRUE(stack2.Empty());
    EXPECT_EQ(stack2.length(), 0);
}

TEST(Stack, PushAndPop) {
    Stack<int> stack;
    stack.Push(1);
    stack.Push(2);
    stack.Push(3);
    EXPECT_EQ(stack.length(), 3);
    EXPECT_EQ(stack.Top(), 3);

    stack.Pop();
    EXPECT_EQ(stack.length(), 2);
    EXPECT_EQ(stack.Top(), 2);
    EXPECT_EQ(stack.Pop(), 2);
    EXPECT_EQ(stack.Pop(), 1);

    EXPECT_THROW(stack.Pop(), std::out_of_range);
}
